private MethodGenerator Method(string key, AccessModifier scope, MethodModifier modifier, bool isOverride, Method nest) { var method = MethodGenerator.Method(scope, modifier, typeof(void), key.Replace(" ", string.Empty)); method.Body(CodeExtensions.Invoke(key, typeof(void), isOverride, GetParameters(method, nest))); return(method); }
public static string MethodHeader(int depth, AccessModifier scope, MethodModifier modifier, Type returnType, string name) { var header = string.Empty; string _modifier = modifier.ToString(); string _scope = scope.ToString(); string _returnType = returnType.Name.ToString(); _scope = _scope.AddLowerUpperNeighboringSpaces(); _scope = _scope.ToLower(); _modifier = _modifier.ToLower(); if (modifier == MethodModifier.None) { _modifier = string.Empty; } if (returnType.DeclaringType != returnType || returnType.DeclaringType != typeof(object)) { if (ToLowerReturnTypes.Contains(returnType)) { _returnType = _returnType.ToLower(); } } header += Indent(depth) + _scope + " " + _modifier + " " + _returnType + " " + name + "(" + ")"; return(header); }
public DomMethod(string name, Modifiers modifiers, MethodModifier MethodModifier, DomLocation location, DomRegion bodyRegion) { this.Name = name; this.Modifiers = modifiers; this.Location = location; this.BodyRegion = bodyRegion; this.MethodModifier = MethodModifier; }
public static string AsString(this MethodModifier modifier) { if (modifier == MethodModifier.None) { return(string.Empty); } return(EnumToLower(modifier)); }
public static MethodGenerator Method(AccessModifier scope, MethodModifier modifier, Type returnType, string name) { var method = new MethodGenerator(); method.scope = scope; method.modifier = modifier; method.name = name; method.returnType = returnType; return(method); }
protected MethodGenerator Method(string key, AccessModifier scope, MethodModifier modifier, Type returnType, string parameters = null, string body = null) { var method = MethodGenerator.Method(scope, modifier, returnType, key.Replace(" ", string.Empty)); if (!string.IsNullOrEmpty(body)) { method.Body(body); } return(method); }
protected MethodGenerator Method(string key, AccessModifier scope, MethodModifier modifier, Type returnType, bool isOverride, string parameters = null) { var method = MethodGenerator.Method(scope, modifier, returnType, key.Replace(" ", string.Empty)); var line1 = CodeBuilder.InitializeVariable("val", returnType); var line2 = CodeExtensions.Invoke(key, returnType, isOverride, parameters); var line3 = CodeBuilder.NullVoidOrNot(returnType, string.Empty, "\n" + CodeBuilder.Return("val")); method.Body(line1 + line2 + line3); return(method); }
public static string MethodHeader(int depth, AccessModifier scope, MethodModifier modifier, Type returnType, string name, Dictionary <string, Type> parameters) { var header = string.Empty; var keys = parameters.Keys.ToListPooled(); var values = parameters.Values.ToListPooled(); var _parameters = string.Empty; for (int i = 0; i < parameters.Count; i++) { _parameters += ((i > 0) ?" " : string.Empty); _parameters += values[i].CSharpName() + " "; _parameters += Patcher.LegalVariableName(keys[i], false) + ((i != parameters.Count - 1) ? "," : string.Empty); } header += "\n"; header += CodeBuilder.Indent(depth) + Patcher.AddLowerUpperNeighboringSpaces(scope.ToString()).ToLower() + " " + ((modifier == MethodModifier.None) ? string.Empty : modifier.ToString().ToLower()) + ((modifier == MethodModifier.None) ? string.Empty : " ") + (returnType == null || returnType == typeof(Void) ? typeof(void).CSharpName() : Ludiq.CSharpNameUtility.CSharpName(returnType)) + " " + name + "(" + _parameters + ")"; return(header); }
public Method New(ClassMacro instance, string name, AccessModifier scope, MethodModifier modifier, Type returnType, ParameterDeclaration[] parameters, bool isMagic = false) { var asset = GetRootAsset(instance); Method _method = null; if (modifier == MethodModifier.Override || modifier == MethodModifier.None && isMagic) { return(Override()); } return(Custom()); Method Override() { asset.Is().NotNull(() => { _method = overrides.Define(previousOverrides, name, (method) => { _method = CreateNest(out addedMethod); _method.name = name; SetNestEntryParameters(_method, parameters); DefineNestMacro(name, _method); Add(_method); AssetDatabase.AddObjectToAsset(_method.macro, asset); addedMethod = true; return(_method); }, (method) => { EnsureParametersMatch(name, parameters); addedMethod = true; SetOverrideMethod(name); _method = method; }); }); if (_method != null) { _method.scope = scope; _method.modifier = modifier; _method.returnType = returnType; _method.isSpecial = isMagic; _method.hasOptionalOverride = true; if (_method.macro.entry.returnType != returnType) { _method.macro.entry.returnType = returnType; _method.macro.entry.DefineReturns(); } _method.macro.hideFlags = HideFlags.HideInHierarchy; } return(_method); } Method Custom() { if (_method != null) { _method.scope = scope; _method.modifier = modifier; _method.returnType = returnType; _method.name = name; _method.isSpecial = false; if (_method.macro.entry.returnType != returnType) { _method.macro.entry.returnType = returnType; } _method.macro.hideFlags = HideFlags.HideInHierarchy; _method.macro.entry.Define(); } return(_method); } Method CreateNest(out bool nestAdded) { var nest = new Method(); nest.Initialize(); nestAdded = true; return(nest); } }